package top.wherewego.vnt;

import top.wherewego.vnt.jni.CallBack;
import top.wherewego.vnt.jni.param.ConnectInfo;
import top.wherewego.vnt.jni.param.DeviceConfig;
import top.wherewego.vnt.jni.param.DeviceInfo;
import top.wherewego.vnt.jni.param.ErrorInfo;
import top.wherewego.vnt.jni.param.HandshakeInfo;
import top.wherewego.vnt.jni.param.PeerClientInfo;
import top.wherewego.vnt.jni.param.RegisterInfo;

import java.util.Arrays;

/**
 * @date: 2024/02/27 15:45
 */
public class Test {
    static {
        System.loadLibrary("vnt_jni");
    }

//    public static void main(String[] args) throws Exception {
//
//        Config config = new Config();
//        config.setToken("1233");
//        config.setName("name");
//        config.setDeviceId("name");
//        config.setServer("txt:text.liaohcai.dns.army");
//        config.setStunServer(new String[]{"stun1.l.google.com:19302"});
//        config.setCipherModel("aes_gcm");
//        config.setPassword("mm9527");
////        config.setDns(new String[]{});
////        config.setDeviceName("tap-w");
////        config.setTap(true);
////        config.setServerEncrypt(true);
//        config.setMtu(1000);
//        config.setIp("10.26.0.110");
//        Vnt vnt = new Vnt(config, new C());
//        Thread.sleep(5000);
//        System.out.println("=====================");
//        System.out.println(Arrays.toString(vnt.list()));
//        Thread.sleep(5000);
////        vnt.await();
//        System.out.println("========= stop");
//        vnt.close();
//        vnt.await();
//        System.out.println("========= stop ------");
//        Thread.sleep(10000);
//    }

    static class C implements CallBack {

        @Override
        public void success() {
            System.out.println("启动成功，从离线变成在线就会触发");
        }

        @Override
        public void createTun(DeviceInfo info) {
            System.out.println("创建虚拟网卡成功，安卓上可以不关心这个");
            System.out.println(info);
        }

        @Override
        public void connect(ConnectInfo info) {
            System.out.println("首次连接或者重连");
            System.out.println(info);
        }

        @Override
        public boolean handshake(HandshakeInfo info) {
            System.out.println("握手响应服务端的版本和 服务端公钥（如果有服务端加密），这里可以验证服务端公钥的正确性，防止篡改");
            System.out.println(info);
            return true;
        }

        @Override
        public boolean register(RegisterInfo info) {
            System.out.println("注册成功，服务端分配ip地址，安卓端要根据这个设置路由，windows/linux/macos vnt会自己设置路由");
            System.out.println(info);
            return true;
        }

        @Override
        public int generateTun(DeviceConfig info) {
            System.out.println("安卓在这里创建vpn，并设置路由、返回vpn fd");
            System.out.println(info);
            // 返回vpn fd
            return 0;
        }

        @Override
        public void peerClientList(PeerClientInfo[] infoArray) {
            System.out.println("用户列表");
            System.out.println(Arrays.toString(infoArray));
        }


        @Override
        public void error(ErrorInfo info) {
            System.out.println("错误信息，对于TokenError/AddressExhausted/IpAlreadyExists/InvalidIp这些错误，需要停止服务，否则会一直重连");
            System.out.println(info);
        }

        @Override
        public void stop() {
            System.out.println("服务停止");
        }
    }
}
